﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.JinShengService;

namespace CommunitySystem.PageView
{
    public partial class BMListControl : UserControl
    {
        private JinShengServiceClient client = new JinShengServiceClient();
        public BMListControl()
        {
            InitializeComponent();

            client.SaveBMFBInfoCompleted += (sender, e) =>
            {
                var status = e.UserState;
                if (e.Error == null)
                    SilverlightMessageBoxLibrary.Message.InfoMessage(status+"成功!");
              
            };

            Load();
        }
        private void Load()
        {
            client.GetBMFBInfoCompleted += new EventHandler<GetBMFBInfoCompletedEventArgs>(client_GetBMFBInfoCompleted);
            client.GetBMFBInfoAsync("");
        }

        void client_GetBMFBInfoCompleted(object sender, GetBMFBInfoCompletedEventArgs e)
        {
            this.dg.ItemsSource = e.Result;
        }


        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            var sel = this.dg.SelectedItem as BMFBInfo;
            BMFBWindow win = new BMFBWindow(sel);
            win.Show();

            win.Closed += new EventHandler(win_Closed);

        }

        void win_Closed(object sender, EventArgs e)
        {
            Load();
        }

        private void btnFB_Click(object sender, RoutedEventArgs e)
        {
            var sel = this.dg.SelectedItem as BMFBInfo;
            sel.Status = "发布";
            client.SaveBMFBInfoAsync(sel, "","发布");
        }

        private void btnJS_Click(object sender, RoutedEventArgs e)
        {
            var sel = this.dg.SelectedItem as BMFBInfo;
            sel.Status = "结束";
            client.SaveBMFBInfoAsync(sel, "","结束");
        }
    }
}
